package com.augurit.wf.common.tag.datetime;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.components.Component;
import org.apache.struts2.views.jsp.ComponentTagSupport;

import com.augurit.common.util.lang.DateUtils;
import com.opensymphony.xwork2.util.ValueStack;

public class WfDateTimeTag extends ComponentTagSupport {
	private static final long serialVersionUID = 666678L;
	
	private String id;
	private String name;
	private String type;
	private String value;
	private String format;		//模式
	private String readOnly;
	private String cssClass;
	private String disabled;	//是否锁定
	private String hidden;		//是否隐藏
	
	
	private String debug;
	private String height;
	private String onblur;
	private String onfocus;
	private String width;
	private String align;
	private String style;
	private String size;
	private String onclick;
	
	private Date date;

	@Override
	public Component getBean(ValueStack stack, HttpServletRequest req,
			HttpServletResponse res) {
		WfDateTime wfDateTime = new WfDateTime(stack);
		wfDateTime.setPrivByElementId(id, req);
		date = (Date)stack.findValue(value);
		return wfDateTime;
	}
	
	/**
	 * 格式化Date时间串
	 * @return
	 */
	private String formatDateTime(){
		if(format == null || format.trim().length() <= 0){
			return DateUtils.dateTimeToString(date, DateUtils.YYYY_MM_DD);
		}
		else{
			return DateUtils.dateTimeToString(date, format);
		}
	}
	
	//获得参数
	protected void populateParams(){
		super.populateParams();
		WfDateTime wfDateTime = (WfDateTime)component;
		wfDateTime.setValue(formatDateTime());
		wfDateTime.setId(id);
		wfDateTime.setName(name);
		wfDateTime.setType(type);
		wfDateTime.setCssClass(cssClass);
		wfDateTime.setAlign(align);
		wfDateTime.setReadOnly(readOnly);
		wfDateTime.setHeight(height);
		wfDateTime.setSize(size);
		wfDateTime.setWidth(width);
		wfDateTime.setAlign(align);
		wfDateTime.setStyle(style);
		wfDateTime.setOnfocus(onfocus);
		wfDateTime.setOnclick(onclick);
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public String getReadOnly() {
		return readOnly;
	}

	public void setReadOnly(String readOnly) {
		this.readOnly = readOnly;
	}

	public String getCssClass() {
		return cssClass;
	}

	public void setCssClass(String cssClass) {
		this.cssClass = cssClass;
	}

	public String getDisabled() {
		return disabled;
	}

	public void setDisabled(String disabled) {
		this.disabled = disabled;
	}

	public String getHidden() {
		return hidden;
	}

	public void setHidden(String hidden) {
		this.hidden = hidden;
	}

	public String getDebug() {
		return debug;
	}

	public void setDebug(String debug) {
		this.debug = debug;
	}

	public String getHeight() {
		return height;
	}

	public void setHeight(String height) {
		this.height = height;
	}

	public String getOnblur() {
		return onblur;
	}

	public void setOnblur(String onblur) {
		this.onblur = onblur;
	}

	public String getOnfocus() {
		return onfocus;
	}

	public void setOnfocus(String onfocus) {
		this.onfocus = onfocus;
	}

	public String getWidth() {
		return width;
	}

	public void setWidth(String width) {
		this.width = width;
	}

	public String getAlign() {
		return align;
	}

	public void setAlign(String align) {
		this.align = align;
	}

	public String getStyle() {
		return style;
	}

	public void setStyle(String style) {
		this.style = style;
	}

	public String getSize() {
		return size;
	}

	public void setSize(String size) {
		this.size = size;
	}

	public String getFormat() {
		return format;
	}

	public void setFormat(String format) {
		this.format = format;
	}
	public String getOnclick() {
		return onclick;
	}

	public void setOnclick(String onclick) {
		this.onclick = onclick;
	}
}
